import  fcgi.Thread;
import  fcgi.Connection;
import  fcgi.Request;
import  fcgi.Exception;

import  tango.math.random.Kiss;

Kiss rnd;

int myrun(FastCGIRequest request)
{
    request.stdout.write ("Content-type: text/html\r\n\r\n");

    switch (rnd.toInt % 4)
    {
    case 0:
        request.stdout.write ("Chosen exception: Array index out of bounds\n");
        char[] foo = new char[3];
        char c = foo[10];
    break;
    case 1:
        request.stdout.write ("Chosen exception: Assertion\n");
        assert (false);
    break;
    case 2:
        request.stdout.write ("Chosen exception: Exception\n");
        throw new Exception ("My Exception");
    break;
    default:
        request.stdout.write ("Chosen Exception: none\n");
    }

    return 0;
}

int main(char[][] args)
{
    rnd = Kiss ();

    FastCGIConnection connection = new FastCGIConnection ();

    return FastCGIThread.loop(connection, &myrun, true, 10);
}
